<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
echo '<h2>Anketa</h2><div class="mod_poll"><ul>';
$query = Registry::get('db')->query("SELECT * FROM {prefix}poll WHERE active = '1' ORDER BY date DESC LIMIT 1");
if ($query->num_rows == 0) {
    echo '<li><strong>Žádná anketa není aktivní !</strong></li>';
} else {
    $data = $query->fetch_array();
    $ip = unserialize($data['ip']);
    $votes = unserialize($data['vote']);
    if (array_search($visitors_online->ipCheck(), (array)$ip, true)) {
        echo '<li><strong>Již jste hlasoval !</strong></li>';
    } else {
        echo '<form action="{url}index.php?q=poll/' . $data['id'] .
            '" method="post">';
        echo '<li><strong>' . $data['question'] . '</strong></li>';
        $question = unserialize($data['answers']);
        foreach ($question as $key => $val) {
            echo '<li><input type="radio" name="vote" value="' . $key .
                '" />' . $val . '</li>';
        }
        echo '<li><input type="submit" value="Odeslat" /></li>';
        echo '</form>';
    }
    
    $vote = 0;
    foreach($votes as $key => $val)
    {
        $vote += $val;
    }
    
    echo '<li><a href="{url}index.php?q=poll/' . $data['id'] . '" >Výsledky (počet hlasů '.$vote.')</a></li>';
    echo '</ul></div>';
}
?>